package cn.wolfcode.shop.cloud.service.impl;

import cn.wolfcode.shop.cloud.mapper.SeckillGoodMapper;
import cn.wolfcode.shop.cloud.mapper.SeckillOrderMapper;
import cn.wolfcode.shop.cloud.service.ISeckillOrderService;
import cn.wolfcode.shop.cloud.service.RedisService;
import cn.wolfcode.shop.cloud.util.MemberKeyPrefix;
import cn.wolfcode.shop.cloud.util.SeckillKeyPrefix;
import domain.OrderInfo;
import domain.SeckillOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SeckillOrderServiceImpl implements ISeckillOrderService {
    @Autowired
    private SeckillOrderMapper seckillOrderMapper;
    @Autowired
    private RedisService redisService;

    @Override
    public SeckillOrder queryByUserIdAndSeckillId(Long userId, Long seckillId) {
        return seckillOrderMapper.queryByUserIdAndSeckillId(userId, seckillId);
    }

    @Override
    public void createSeckillOrder(Long userId, Long seckillId, String orderNo) {
        SeckillOrder seckillOrder = new SeckillOrder();
        seckillOrder.setOrderNo(orderNo);
        seckillOrder.setSeckillId(seckillId);
        seckillOrder.setUserId(userId);
        seckillOrderMapper.save(seckillOrder);
        //存储到redis当中
        //seckill_order:userId:seckillId
        redisService.set(SeckillKeyPrefix.SECKILL_ORDER,userId+":"+seckillId,true);
    }

}
